package com.bicon.botu.core.dto;


import lombok.Data;

import java.util.List;

/**
 * @auther 裴志鹏
 * @date 2017/9/28 11:21
 */
@Data
public class PageDTO<T> {
    /**
     * 总记录数
     */
    private int total;

    /**
     * 每页显示条数
     */
    private int size = 10;

    /**
     * 总页数
     */
    private int pages;

    /**
     * 当前页
     */
    private int current = 1;

    /**
     * 查询数据列表
     */
    private List<T> records;

    /**
     * 开始记录数
     */
    private int startIndex;

    /**
     * 结束记录数
     */
    private int endIndex;

    public PageDTO(int current, int size, int total) {
        this.current = current;
        this.size = size;
        this.total = total;
        setRangeParameter(current, size);
        getTotalPages();
    }

    public void getTotalPages() {
        if (this.current % this.size == 0) {
            this.pages = this.total / this.size;
        } else {
            this.pages = this.total / this.size + 1;
        }
    }

    public void setRangeParameter(int current, int size) {
        this.startIndex = (current - 1) * size;
        this.endIndex = startIndex + size - 1;
    }
}
